<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>easyAPI文档解析</title>
	<script type="text/javascript" src="../src/jquery-1.9.1.js"></script>
	<script type="text/javascript" src="../src/bootstrap/dist/js/bootstrap.js"></script>
	<link rel="stylesheet" href="../src/bootstrap/dist/css/bootstrap.css">
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
				<div class="form-group">
					<label for="name">xml文档</label>
					<textarea  id="htmlTextarea" class="form-control" rows="30"></textarea>
				</div>
			</div>
			<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
				<div class="form-group">
					<label for="name">结果</label>
					<textarea id="result" class="form-control" rows="30"></textarea>
				</div>
			</div>
		</div>
		<div class="row">
			<button type="button" class="btn btn-primary" onclick="javascript:htmlToOCObject();">转化成接口</button>
		</div>
	</div>
</body>

<script type="text/javascript">
	// 转OC对象
	function htmlToOCObject(){
		try{

			// 获取html内容
			var html = $("#htmlTextarea").val();
			// 转换成dom
			var parser = new DOMParser();
			var doc = parser.parseFromString(html, "text/html");
 			// 转换成jquery对象
 			var $v=$(doc); //jQuery对象
 			var ocStr = '';
 			$v.find("table").eq(0).find("tbody tr:gt(0)").each(function(index){
 				var act = $(this).find("td").eq(2).text();
 				ocStr =  ocStr + "#define Action_" + act + "        " + '@"'+ act + '"'  + " // " +  $(this).find("td").eq(0).find("a").text() + "\n";
 			});
			$("#result").val(ocStr);
		}catch(e){
			$("#result").val('出错啦！！！！！！！！！！！！！！');
		}
		
	}
</script>
</html>